home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_1 / dr / source / paul.h < prev    next >
C/C++ Source or Header  |  1993-11-21  |  6KB  |  233 lines

  1. /*
  2. The following declarations are used in most every program written by Paul
  3. Kienitz.  Generally, I use a symbol table file which includes exec/exec.h,
  4. libraries/dosextens.h, and string.h, and exec and dos prototypes.  I have
  5. two versions: one includes only that and the other adds intuition/intuition.h
  6. and most of the other prototypes.
  7.  
  8. This include file is no longer usable with pre-ANSI Aztec.  If Aztec is used it
  9. must be 5.0 or newer.
  10.  
  11. Note to myself: modern SAS/C defines LATTICE, LATTICE_50, SASC, SASC_510, and
  12. __VERSION__ = 5 or 6.  Aztec 5.2 sets __VERSION__ to 500.
  13. */
  14.  
  15. #ifndef PAUL_DOT_AITCH
  16. #define PAUL_DOT_AITCH
  17.  
  18. #ifdef __STDIO_H
  19. #  define put(S) fputs(S, stdout)
  20. #endif
  21.  
  22.  
  23. #if __STDC__
  24. #  define _ANSI_C
  25. #else
  26. #  ifdef AZTEC_C
  27. #    define _ANSI_C
  28. #  endif
  29. #endif
  30.  
  31.  
  32. #ifdef _ANSI_C
  33. #  define _PROTO(X) X
  34. #  define VOLATILE volatile
  35. #  define CONST const
  36. #  define SIGNED signed
  37. #else
  38. #  define _PROTO(X) ()
  39. #  define VOLATILE 
  40. #  define CONST
  41. #  define SIGNED
  42. #endif
  43.  
  44.  
  45. #ifdef AZTEC_C
  46.  
  47. #  ifdef INTUITION_INTUITION_H
  48.  
  49. #    define OpenWorkBench       ____00argleBArGlE__
  50.  
  51. #    include <functions.h>    /* define inline calls of most rom functions */
  52.  
  53. #    undef OpenWorkBench
  54. #    undef GetDefaultPubScreen
  55. struct Screen *OpenWorkBench(void);            /* BOOL in clib/... */
  56. #    pragma amicall(IntuitionBase, 0xD2, OpenWorkBench())
  57.  
  58. #  else
  59.  
  60. #    include <clib/exec_protos.h>
  61. #    include <clib/dos_protos.h>
  62. #    include <clib/timer_protos.h>
  63. #    include <clib/diskfont_protos.h>
  64. #    include <pragmas/exec_lib.h>
  65. #    include <pragmas/dos_lib.h>
  66. #    include <pragmas/timer_lib.h>
  67. #    include <pragmas/diskfont_lib.h>
  68.  
  69. /* with 2.0 includes those are about all of the commonly needed ones which we
  70. can manage to pull in without bringing the weight of intuition/intuition.h
  71. crashing down on our heads. */
  72.  
  73. #  endif
  74.  
  75. #endif
  76.  
  77.  
  78. #ifdef LIBRARIES_MATHFFP_H
  79.  
  80. /* too many Commodore includes which have no need for floating point pull this
  81. in.  It #defines a bunch of floating point functions so that it becomes
  82. impossible to use the linker library functions of the same name. */
  83.  
  84. #  undef sin
  85. #  undef cos
  86. #  undef tan
  87. #  undef asin
  88. #  undef acos
  89. #  undef atan
  90. #  undef sinh
  91. #  undef cosh
  92. #  undef tanh
  93. #  undef exp
  94. #  undef log
  95. #  undef log10
  96. #  undef pow
  97. #  undef sqrt
  98. #  undef fabs
  99. #  undef floor
  100. #  undef ceil
  101.  
  102. #endif
  103.  
  104.  
  105. /* This stuff has to be BELOW functions.h now or the #defines get it confused: */
  106.  
  107. #define null   ((void *) 0L)
  108. #define maxint 0x7FFFFFFFL
  109. #define minint 0x80000000L
  110. /* uppercase is a pain in the wazoo */
  111.  
  112. #define bip(T, B) ((T *) ((B) << 2))
  113. #define gbip(B)   bip(void, B)
  114. /* B is expected to be of type BPTR or BSTR. */
  115.  
  116. typedef short bool;        /* change this to ubyte and see what breaks? */
  117. #define false ((bool) 0)
  118. #define true  ((bool) 1)
  119.  
  120. typedef unsigned short ushort;
  121. typedef unsigned long  ulong;
  122. typedef unsigned char  ubyte;
  123.  
  124. typedef void *adr;
  125. typedef SIGNED char *str;
  126. typedef ubyte *ustr;
  127.  
  128. typedef void (*PVF)();        /* pointer to void function */
  129. typedef int  (*PIF)();        /* pointer to function returning int */
  130.  
  131.  
  132. #define bit(B) (1L << (B))
  133.  
  134. #define import extern
  135. #define PUBLIC
  136. #ifndef private
  137. #  define private static
  138. #endif
  139.  
  140.  
  141. #ifndef _SIZE_T
  142. #  define _SIZE_T
  143. typedef unsigned long size_t;
  144. #endif
  145.  
  146.  
  147. /* AND NOW, convenience stuff:::::::::::::::::::: */
  148.  
  149. #ifdef EXEC_MEMORY_H
  150.  
  151. #  define MEMF_CP     (MEMF_CHIP | MEMF_PUBLIC)
  152. #  define MEMF_CZ     (MEMF_CHIP | MEMF_CLEAR)
  153. #  define MEMF_PZ     (MEMF_PUBLIC | MEMF_CLEAR)
  154. #  define MEMF_CPZ    (MEMF_CHIP | MEMF_PUBLIC | MEMF_CLEAR)
  155.  
  156. #  define Alloc(S)    AllocMem((ulong) (S), 0L)
  157. #  define AllocC(S)   AllocMem((ulong) (S), MEMF_CHIP)
  158. #  define AllocP(S)   AllocMem((ulong) (S), MEMF_PUBLIC)
  159. #  define AllocZ(S)   AllocMem((ulong) (S), MEMF_CLEAR)
  160. #  define AllocCP(S)  AllocMem((ulong) (S), MEMF_CP)
  161. #  define AllocCZ(S)  AllocMem((ulong) (S), MEMF_CZ)
  162. #  define AllocPZ(S)  AllocMem((ulong) (S), MEMF_PZ)
  163. #  define AllocCPZ(S) AllocMem((ulong) (S), MEMF_CPZ)
  164. #  define NEW(A)      (A = AllocMem(sizeof(*(A)), 0L))
  165. #  define NEWC(A)     (A = AllocMem(sizeof(*(A)), MEMF_CHIP))
  166. #  define NEWP(A)     (A = AllocMem(sizeof(*(A)), MEMF_PUBLIC))
  167. #  define NEWZ(A)     (A = AllocMem(sizeof(*(A)), MEMF_CLEAR))
  168. #  define NEWCP(A)    (A = AllocMem(sizeof(*(A)), MEMF_CP))
  169. #  define NEWCZ(A)    (A = AllocMem(sizeof(*(A)), MEMF_CZ))
  170. #  define NEWPZ(A)    (A = AllocMem(sizeof(*(A)), MEMF_PZ))
  171. #  define NEWCPZ(A)   (A = AllocMem(sizeof(*(A)), MEMF_CPZ))
  172.  
  173. #  ifdef PAUL_OLD_NEW
  174. #    define New(T)      ((T *) AllocMem(sizeof(T), 0L))
  175. #    define MewC(T)     ((T *) AllocMem(sizeof(T), MEMF_CHIP))
  176. #    define NewP(T)     ((T *) AllocMem(sizeof(T), MEMF_PUBLIC))
  177. #    define NewZ(T)     ((T *) AllocMem(sizeof(T), MEMF_CLEAR))
  178. #    define NewCP(T)    ((T *) AllocMem(sizeof(T), MEMF_CP))
  179. #    define NewCZ(T)    ((T *) AllocMem(sizeof(T), MEMF_CZ))
  180. #    define NewPZ(T)    ((T *) AllocMem(sizeof(T), MEMF_PZ))
  181. #    define NewCPZ(T)   ((T *) AllocMem(sizeof(T), MEMF_CPZ))
  182. #    define Free(T, A)  FreeMem(A, sizeof(T))
  183. #  endif
  184.  
  185. #endif
  186.  
  187. #define FREE(A)     FreeMem(A, sizeof(*(A)))
  188.  
  189.  
  190. #ifdef DOS_DOS_H
  191. #  define LIBRARIES_DOS_H
  192. #endif
  193. #ifdef DOS_DOSEXTENS_H
  194. #  define LIBRARIES_DOSEXTENS_H
  195. #endif
  196.  
  197. #ifdef LIBRARIES_DOS_H
  198.  
  199. #  define RLock(F) Lock((ustr) F, (long) ACCESS_READ)
  200. #  define WLock(F) Lock((ustr) F, (long) ACCESS_WRITE)
  201. #  define OOpen(F) Open((ustr) F, (long) MODE_OLDFILE)
  202. #  define NOpen(F) Open((ustr) F, (long) MODE_NEWFILE)
  203.  
  204. #endif
  205.  
  206. #define OpenL(n) (adr) OldOpenLibrary((ustr) n ".library")
  207.  
  208. #define Forbid() ((*((ubyte **) 4))[295]++)
  209. /* as efficient as assembly; Aztec turns that into two instructions. */
  210.  
  211. #ifdef LIBRARIES_DOSEXTENS_H
  212.  
  213. #  define ThisProcess() ((*((struct Process ***) 4))[69])
  214. /* equivalent to (struct Process *) SysBase->ThisTask, two instructions. */
  215.  
  216. #endif
  217.  
  218.  
  219. #ifdef AZTEC_C
  220. #  define strcpy _BUILTIN_strcpy
  221. #  define strcmp _BUILTIN_strcmp
  222. #  define strlen _BUILTIN_strlen
  223. str strcpy(str _dst, const str _src);
  224. int strcmp(const str _s1, const str _s2);
  225. size_t strlen(const str _s);
  226. #endif
  227.  
  228. #ifndef offsetof
  229. #  define offsetof(type,memb) ((size_t)((unsigned long)&((type *)0)->memb))
  230. #endif
  231.  
  232. #endif PAUL_DOT_AITCH
  233.